import { RankingModel } from './model.js';
var model = new RankingModel();
var area = require('../../utils/area.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    start:0,
    current_city:'苏州市',
    areaList: area.default,
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList();
  },
  // 选择地址
  changeArea: function () {
    this.setData({ select_address: true })
  },
  // 关闭地址选择
  onClose: function () {
    this.setData({
      select_address: false
    });
  },
  // 选择地址
  onSelectOk: function (e) {
    var detail = e.detail.values;
    var city=detail[1].name;
    this.setData({
      current_city:city,
      list:[],
      start:0
    })
    this.getList();
    this.onClose();
  },
  // 搜索列表
  searchData: function (e){
    if(e.detail.length>0){
      this.data.current_city = e.detail
    }
    this.setData({
      list:[],
      start:0
    })
    this.getList();
  },
  // 设置搜索值
  setValue:function(e){
    this.setData({value:e.detail})
  },
  // 获取城市数据
  getList(){
    var city=this.data.current_city
    let start=this.data.start
    model.getList({city,start},(res) => {
      let list=this.data.list.concat(res.data.list);
      let start=list.length
      this.setData({
        list,
        start
      })
    })
  },

  onLower(e){
    this.getList();
  },

})